<div class='form-item'>
    <!-- <link rel="stylesheet" href="__ADDONROOT__/js/artdialog/ui-dialog.css"> -->
    <script type="text/javascript" src="__ADDONROOT__/js/artdialog/dialog-min.js"></script>
    <script type="text/javascript" src="__ADDONROOT__/js/artdialog/dialog-plus-min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=yOM9aUrj57mN7Y2tz67Wr9BZ"></script>
    <!-- <div>坐标格式：lng,lat,zoom</div>-->
    <style>
        .search-result {
            width: 239px;
            max-height: 565px;
            overflow-y: auto;
        }

        .tangram-suggestion-main {
            z-index: 9999;
        }

    .bg{
    display: block;
    width: 250px;
    height: 48px;
    border: 1px solid #ddd;
    padding: 0 10px;
    font-size: 14px;
    line-height: 16px;
    color: #333333;
}



    </style>


                <table>
                
                    <tr><td><div class="ctbb-zd">坐标信息：</div></td>
                    <td><input type="text" class="bg" id="input_{$param['name']}" name="{$param['name']}" value="{$param['value']}"></td>
                    <td><a class="jo" id="map_box_{$param['name']}_a"><div class="ctbb-zd" id="hh"style="color:blue;">定位</div></a></td>
                </tr>
                    <div class="divclear"></div>
                </table>   


    <script type="text/javascript">
        $(function () {
            !function () {
                //map元素
                var mapBoxDialog = null;
                //jq el
                var mapValueInput = $("#input_{$param['name']}");
                var mapValue = mapValueInput.val();
                mapValue = mapValue.split(',');
                var zoomDefault = parseInt(mapValue[2]);
                zoomDefault = zoomDefault > 0 ? zoomDefault : 15;
                var mapId = "map_box_{$param['name']}";
                var mapA = $("#map_box_{$param['name']}_a");
                var map = null;
                var infoDialog = null;
                var infoDialogTimeout = null;

                var searchDialog = null;
                var searchInputId = "searchInput_{$param['name']}";
                var searchAuto = null;
                var myValue;
                var initSearchDialog = function () {
//                    console.info(searchDialog);
                    if (searchDialog != null) {
                        searchDialog.close().remove();
                        searchDialog = null;
                        return;
                    }
                    searchDialog = dialog({
                        align: 'right top',
                        content: '<div><label>地点：<input id="' + searchInputId + '"></label></div>'
                    });
                    searchDialog.show(document.getElementById('content:' + mapId));
                    searchAuto = new BMap.Autocomplete({"input": searchInputId, "location": map});
                    searchAuto.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
                        var str = "";
                        var _value = e.fromitem.value;
                        var value = "";
                        if (e.fromitem.index > -1) {
                            value = _value.province + _value.city + _value.district + _value.street + _value.business;
                        }
                        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                        value = "";
                        if (e.toitem.index > -1) {
                            _value = e.toitem.value;
                            value = _value.province + _value.city + _value.district + _value.street + _value.business;
                        }
                        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
//                        console.info(str);
                    });
                    searchAuto.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
                        var _value = e.item.value;
                        myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
                        setPlace();
                    });
                    function setPlace() {
                        map.clearOverlays();    //清除地图上所有覆盖物
                        function myFun() {
                           //console.info(local.getResults());
                            if (local.getResults()._pois.length > 0) {
                                var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
//                                console.info(pp);
                                setPosition(pp.lng, pp.lat);
                                map.centerAndZoom(pp, zoomDefault);
                                map.addOverlay(new BMap.Marker(pp));    //添加标注
                            } else {
                                showInfoDialog('无定位数据，请重新搜索');
                            }
                        }

                        var local = new BMap.LocalSearch(map, { //智能搜索
                            onSearchComplete: myFun
                        });
                        //console.log(local);
                        local.search(myValue);
                    }
                };

                mapA.bind('click', function () {
                    mapBoxDialog = dialog({
                        id: mapId,
                        title: '地图定位',
                        content: "<div style='width: 100%;height: 100%;'></div>",
                        width: 600,
                        height: 400,
                        onremove: function () {
                            if (searchDialog && searchDialog.close) {
                                searchDialog.close().remove();
                                searchDialog = null;
                            }
                        },
                        button: [
                            {
                                value: '搜索',
                                callback: function () {
                                    initSearchDialog();
                                    return false;
                                }
                            }
                        ],
                        onshow: function () {
                            initMap();
                        }

                    });
                    mapBoxDialog.show();
                });
                var setPosition = function (lng, lat) {
                    mapValue[0] = lng;
                    mapValue[1] = lat;
                    mapValue[2] = zoomDefault;
                    mapValueInput.val(mapValue.join(','));
                    showInfoDialog();
                }
                var setZoom = function (zoom) {
                    if (mapValue[0] > 0 && mapValue[1] > 0) {
                        mapValue[2] = zoom;
                        mapValueInput.val(mapValue.join(','));
                    }
                }
                var showInfoDialog = function (msg) {
                    msg = msg ? msg : '定位成功';
                    if (infoDialog != null) {
                        infoDialog.close().remove();
                        clearTimeout(infoDialogTimeout);
                    }
                    infoDialog = dialog({
                        align: 'right',
                        content: msg
                    });
                    infoDialog.show(document.getElementById('content:' + mapId));
                    infoDialogTimeout = setTimeout(function () {
                        infoDialog.close().remove();
//                        console.info('remove');
                    }, 1500);
                };
                var initMap = function () {
                    map = new BMap.Map('content:' + mapId);          // 创建地图实例
                    var point = new BMap.Point(116.404, 39.915);  // 创建点坐标
                    var marker = null;
                    map.centerAndZoom(point, 15);

                    //控件
                    map.addControl(new BMap.NavigationControl());
                    map.addControl(new BMap.ScaleControl());
                    map.addControl(new BMap.OverviewMapControl());
                    map.addControl(new BMap.MapTypeControl());
                    //事件
                    map.enableScrollWheelZoom(true);
//                    设置定位
                    var fetchPosition = function (e) {
                        createMark(e.point.lng, e.point.lat);
                        setPosition(e.point.lng, e.point.lat);
                    };
//                    设置缩放级别
                    var fetchZoom = function () {
                        setZoom(this.getZoom());
                    };
                    map.addEventListener("click", fetchPosition);
                    map.addEventListener("zoomend", fetchZoom);

//                    创建标注
                    var createMark = function (lng, lat) {
                        clearMark();
                        marker = new BMap.Marker(new BMap.Point(lng, lat));
                        map.addOverlay(marker);
                    }
//                    清理标注
                    var clearMark = function () {
                        map.clearOverlays();
                    }

//                    ip定位城市
                    var setCity = function (result) {
                        var cityName = result.name;
                        map.setCenter(cityName);
                        if (mapValue[0] > 0 && mapValue[1] > 0) {
                            setTimeout(function(){
                                var point=new BMap.Point(mapValue[0], mapValue[1]);
                                map.centerAndZoom(point, zoomDefault);
                                map.setCenter(point);
                                createMark(mapValue[0], mapValue[1]);
                            },200);
                        }
                    }
                    var myCity = new BMap.LocalCity();
                    myCity.get(setCity);
                };
            }();
        });
    </script>
</div>